#include "painterwin.h"
#include "ui_painterwin.h"

#include <QDebug>
#include <QPainter>
#include <math.h>
PainterWin::PainterWin(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::PainterWin)
{
    ui->setupUi(this);
    this->x = 200;
    this->y = 100;

}

PainterWin::~PainterWin()
{
    delete ui;
}

void PainterWin::paintEvent(QPaintEvent *event)
{
    static int i =0;
    qDebug()<<"绘图"<<i++;

    //绘画工具
    QPainter painter(this);  //创建一个绘图对象，后期绘制在this上

    QPen pen = painter.pen();//获取工具中的画笔
    pen.setWidth(5);  //线宽
    pen.setColor(Qt::green);  //线颜色

    pen.setCapStyle(Qt::RoundCap);  //线头圆角
    painter.setPen(pen);

    painter.drawLine(x,y,200,200);  //绘制直线


    pen.setWidth(10);  //线宽
    pen.setColor(Qt::red);  //线颜色

    pen.setCapStyle(Qt::RoundCap);


    painter.setPen(pen);


    painter.drawLine(150,200,200,200);


    //画圆
    pen.setWidth(10);
    pen.setColor(Qt::blue);
    pen.setCapStyle(Qt::RoundCap);
    painter.setPen(pen);

    painter.drawEllipse(QPoint(200,200),150,150);

    painter.drawEllipse(QPoint(200,200),163,163);


    //画文字
    painter.drawText(x,y,"hello");










}

void PainterWin::on_pushButton_clicked()
{
    //x*x+y*y = 100*100;
    x+=2;
    y++;
    update();


}
